//index.js
//获取应用实例
const app = getApp();
var ea = require('../../utils/each.js');

Page({
  data: {
    gengxin:false,
    sousuo: app.data.imgurl +'sou.png',
    huodongjingxin: app.data.imgurl + "swiper.png",
    taoxin: app.data.imgurl + "appreciate.png",
    taoxins: app.data.imgurl + "hongxin.png",
    imgUrls: [app.data.imgurl +"swiper.png", app.data.imgurl +"swiper1.png", app.data.imgurl +"swiper.png", app.data.imgurl +"swiper1.png"],
    // imgUrl:[],
    autoplay:true,
    indicatorDots: true,
    interval: 5000,
    duration: 1000,
    circular:true,
    lunbo: app.data.imgurl +"lunbo.png",
    otherswiper:[
      "46幅国际金奖摄影作品出炉！",
      "46幅国际金奖摄影作品出炉！",
    ],
    exhibition: [
      { src: app.data.imgurl +"exhibition1.png", content: "新闻资讯" },
      { src: app.data.imgurl +"exhibition2.png", content: "作品展示" }, 
      { src: app.data.imgurl +"exhibition3.png", content: "组织架构" }, 
      { src: app.data.imgurl +"exhibition4.png", content: "会员服务" },
      { src: app.data.imgurl + "exhibition5.png", content: "会员动态" }
     ],
    rightarrow:app.data.imgurl +"rightarrow.png",  //右箭头
    newactive:app.data.imgurl +"newactive.png" , //  最新活动
    newlatests: [{ src: app.data.imgurl +"swiper3.png", title:"2019“伯奇杯”中国创意摄影展活动",number:"3000"},
      { src: app.data.imgurl +"swiper3.png", title: "2019“伯奇杯”中国创意摄影展活动", number: "3000" },
      { src: app.data.imgurl +"swiper3.png", title: "2019“伯奇杯”中国创意摄影展活动", number: "3000" },
      { src: app.data.imgurl +"swiper3.png", title: "2019“伯奇杯”中国创意摄影展活动", number: "3000" }
    ],
    fire:app.data.imgurl +"fire.png", // 火
    lefttop:app.data.imgurl +"lefttop.png", //左上角
    trophy:app.data.imgurl +"trophy.png",//奖杯
    frequnecy:app.data.imgurl +"worksnumbert.png",// 作品数量
    matchs:[
      {src: app.data.imgurl +"swiper.png", title: "2019自然风景展", reward: "2000元现金+证书", date: "8月14日 - 8月30日", frequnecy:"21314"},

      {src: app.data.imgurl +"swiper.png", title: "2018自然风景展", reward: "5000元现金+证书", date: "8月14日 - 8月30日", frequnecy: "21314" }
    ],
     medal: app.data.imgurl +"medal.png",// 奖牌
    worksd:[ 
      { headsrc: app.data.imgurl + "headimg.png", appreciatesrc: app.data.imgurl +"appreciate.png",type: "0", src: app.data.imgurl +"2017123101.mp4" ,title:"来自炎炎夏日去大山里避暑的旅拍混剪",label:"#多媒体摄影",comment:"20",appreciate:"100",comments:[{type:"0",fname:"胡杰",sname:"张飞",content:"消息不错"}]},
      { headsrc: app.data.imgurl + "headimg.png", appreciatesrc: app.data.imgurl + "appreciate.png",type: "1", src: [app.data.imgurl +"swiper1.png", app.data.imgurl +"swiper1.png"], title: "来自炎炎夏日去大山里避暑的旅拍混剪", label: "#多媒体摄影", comment: "20", appreciate: "100", comments: [{ type: "0", fname: "胡杰", sname: "张飞", content: "消息不错" }] }

    ],
    comment:app.data.imgurl +"comment.png", //评论图
    appreciate:app.data.imgurl +"appreciate.png", //赞图
    hongappreciate: app.data.imgurl + "collectiontrue.png" //赞图
  },

  //点击图片预览
  previewimg: function (e) {
    var url = e.currentTarget.dataset.url;
    console.log(url);
    // var ins = this.data.worksd[1].src;
    wx.previewImage({
      current: 1,
      urls: [url]
    })
  },

  //作品详情
  toworksd: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/pxqworks/pxqworks?id='+id,
    })
  },
  //跳转搜索页面
  sousuotiao:function(){
    wx.navigateTo({
      url: '/pages/sou/sou',
    })
  },


  //点赞
  appericiates:function(e){
    var that=this;
    var id = e.currentTarget.dataset.id;
    var user = wx.getStorageSync('user');
    if(!user){
      wx.showModal({
        title: '提示',
        content: '你确定去登录吗?',
        success:function(res){
          // console.log(res);
          if (res.confirm){
            wx.navigateTo({
              url: '/pages/login/login',
            })
          }
        }
      })
      return;
    }
    wx.request({
      url: app.data.url +'sheyingjia/Xzuoping1/dianzan',
      data:{token:user.token,id:id},
      method:"POST",
      success:function(res){
        var data = res.data;
        if(data.code==200){
          var worksd = that.data.worksd;
          var newworksd = [];
          ea.each(worksd,function(i,v){
            if(v.id==id){
              v.wdz = 1;
              v.dianzan = data.data;
            }
            newworksd.push(v);
          })
          that.setData({ worksd:newworksd});
        }else if(data.code==206){
          wx.navigateTo({
            url: '/pages/login/login',
          })
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none'
          })
        }
      }
    })
  
  },

  //首页的四个资讯 作品 小版块
  into:function(e){
   console.log(e)
    var e = e.currentTarget.dataset.index;
    console.log(e)
  if(e==0){
    wx.switchTab({
      url: '/pages/newsinformation/newsinformation'
    })
  }else if (e==1){
    wx.switchTab({
      url: '/pages/works/works'
    })
  }else if(e==2){
    wx.navigateTo({
      url: '/pages/organizationalstucture/organizationalstucture',
    })
  }else if(e==3){
    wx.navigateTo({
      url: '/pages/member/member',
    })
  } else if (e==4) {
    wx.navigateTo({
      url: '/pages/huiyuandongtai/huiyuandongtai',
    })
  }


  },

  //更多活动
  morehuodong:function(){
    wx.switchTab({
      url: '/pages/newsinformation/newsinformation'
    })
  },
   //活动详情
  xqactivity:function(e){
    // console.log(e)
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/xqactivity/xqactivity?id='+id,
    })
  },
  //查看比赛详情
  xqmatch:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/xqmatch/xqmatch?id='+id,
    })
  },
  
  onLoad:function(){
    var that = this;
    wx.showLoading({
      title: '检测更新中',
    })
    ea.toUpdata(function(res){
      wx.hideLoading();
      that.setData({ gengxin:true});
      // that.getdata();
    })
    
  },
  getdata:function(func){
    var that = this;
    var user = wx.getStorageSync('user');
    var tiaojian = {};
    if(user){
      tiaojian.token = user.token;
    }
    wx.request({
      url: app.data.url + 'sheyingjia/Xindex1/getindex',
      method: "POST",
      data: tiaojian,
      success: function (res) {
        console.log(res);
        if(func){
          func();
        }
        var data = res.data;
        if (data.code == 200) {
          console.log(data);
          that.setData({
            imgUrls: data.data.banner,
            newlatests: data.data.huodong,
            matchs: data.data.bisai,
            worksd: data.data.zuoping,
            otherswiper: data.data.xitong,
          })
        } else {
          wx.showToast({
            title: data.msg,
            icon: 'none'
          })
        }
      }
    })
  },
  onShow:function(){
    this.getdata();
  },
  onPullDownRefresh:function(){
    console.log('下拉刷新');
    this.getdata(function(){
      wx.stopPullDownRefresh();
    });
    
  }

})
